package cn.yqx.bankshop.order.controller;

import cn.yqx.bankshop.order.page.PageRequest;
import cn.yqx.bankshop.order.page.PageResult;
import cn.yqx.bankshop.order.service.TrackService;
import cn.yqx.bankshop.result.Result;
import cn.yqx.bankshop.result.ResultCode;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 我的轨迹
 * @author LU
 * @createTime 2021-05-08 10:39
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/track")
public class TrackController {
    private static final String PAGE_REQUEST_KEY = "pageRequest" ;
    private static final String PARAMETER_KEY = "parameter" ;
    @Autowired
    TrackService trackService ;
    @RequestMapping(value = "get_all_track",method = RequestMethod.POST)
    public Object getAllTrack(@RequestBody JSONObject json){
        Result result ;
        try{
            result = Result.success() ;
            PageRequest pageRequest = JSON.parseObject(json.getJSONObject(PAGE_REQUEST_KEY).toJSONString(), PageRequest.class) ;
            JSONObject parameter = json.getJSONObject(PARAMETER_KEY) ;
            PageResult pageResult = trackService.getAllTrack(pageRequest,parameter);
            result.setData(pageResult);
        }catch (Exception e) {
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR) ;
            log.info(" error : {} ",e);
        }

        return result ;
    }
}
